package hl.action;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.springframework.beans.factory.annotation.Autowired;

import com.opensymphony.xwork2.ModelDriven;

import hl.pageModel.Json;
import hl.pageModel.PcOperator;
import hl.service.PcOperatorService;

@Namespace("/")
@Action(value = "pcOperatorAction")
public class PcOperatorAction extends BaseAction implements ModelDriven<PcOperator> {

	PcOperator pcOperator = new PcOperator();

	private PcOperatorService pcOperatorService;

	@Override
	public PcOperator getModel() {
		return pcOperator;
	}

	public PcOperatorService getPcOperatorService() {
		return pcOperatorService;
	}

	@Autowired
	public void setPcOperatorService(PcOperatorService pcOperatorService) {
		this.pcOperatorService = pcOperatorService;
	}

	public void saveOp() {
		Json j = new Json();
		try {
			pcOperatorService.save(pcOperator);
			j.setSuccess(true);
			j.setMsg("添加成功");

		} catch (Exception e) {
			j.setMsg(e.getMessage());
		}
		super.writeJson(j);
	}

	public void login() {
		PcOperator u = pcOperatorService.login(pcOperator);
		Json j = new Json();
		if (u != null) {
			j.setSuccess(true);
			j.setMsg("登录成功");
		} else {
			j.setMsg("登录失败！用户名或密码错误");
		}
		super.writeJson(j);
	}
}
